/*
2021-7-12
https://www.acwing.com/problem/content/1022/
*/
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
const int N=30,M=80;
int f[N][M];

int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    memset(f,0x3f,sizeof f);
    f[0][0]=0;
    
    while(k--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        for(int i=n;i>=0;i--)
            for(int j=m;j>=0;j--)
                f[i][j]=min(f[i][j],f[max(0,i-a)][max(0,j-b)]+c);
    }
    cout<<f[n][m]<<endl;
    return 0;
}
